<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-row :gutter="10">
        <el-col :span="4">
          <el-form-item label="账户ID" prop="userId">
            <el-input
              size="small"
              v-model="queryParams.userId"
              style="width: 100%"
              placeholder="请输入用户账户ID"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="账户名称" prop="userName">
            <el-input
              size="small"
              v-model="queryParams.userName"
              style="width: 100%"
              placeholder="请输入账户名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="用户电话" prop="userPhone">
            <el-input
              v-model="queryParams.userPhone"
              style="width: 100%"
              placeholder="请输入用户电话"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="用户IP属地" prop="userIp">
            <el-input
              size="small"
              v-model="queryParams.userIp"
              placeholder="请输入用户IP属地"
              clearable
              style="width: 100%"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="是否重保用户" prop="userType">
            <el-select
              clearable
              v-model="queryParams.userType"
              style="width: 100%"
              placeholder="请选择是否重保用户"
            >
              <el-option label="是" value="重保用户"></el-option>
              <el-option label="否" value="非重保用户"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>

    <el-row :gutter="10" class="mb8" style="margin: 0">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:user:add']"
          >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:user:edit']"
          >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:user:remove']"
          >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:user:export']"
          >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          class="inBtn"
          icon="el-icon-edit-outline"
          size="mini"
          @click="handleAcquisition"
          v-hasPermi="['system:user:export']"
          >批量采集
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          class="inBtn"
          icon="el-icon-edit-outline"
          size="mini"
          @click="handleAcquisition"
          v-hasPermi="['system:user:export']"
          >全部采集
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          class="inBtn"
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          class="inBtn"
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleImport"
          >批量导入</el-button
        >
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="userList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />

      <!-- 自增主键 -->
      <!-- <el-table-column label="自增主键" align="center" prop="id" /> -->
      <el-table-column label="账户id" align="center" prop="userId" />
      <el-table-column label="账户名称" align="center" prop="userName" />
      <!-- 账号类型 -->
      <el-table-column label="账号类型" align="center" prop="userType" />
      <!-- <el-table-column
        label="社交账号昵称"
        align="center"
        prop="userNickname"
      /> -->
      <el-table-column label="用户电话" align="center" prop="userPhone" />
      <el-table-column label="用户IP属地" align="center" prop="userIp" />
      <el-table-column label="用户关注量" align="center" prop="userFocusNum" />
      <el-table-column label="用户粉丝量" align="center" prop="userFansNum" />
      <el-table-column label="家庭住址" align="center" prop="userHomeAddr" />
      <el-table-column
        label="操作"
        align="center"
        width="400"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="toDetailsPage(scope.row)"
            v-hasPermi="['system:user:edit']"
            >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCaiji(scope.row)"
            v-hasPermi="['system:user:remove']"
            >采集
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:user:edit']"
            >修改
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:user:remove']"
            >删除
          </el-button>
          <el-button
            v-if="!scope.row.token || !scope.row.authTime"
            size="mini"
            type="text"
            icon="el-icon-switch-button"
            @click="handleAuth(scope.row)"
            v-hasPermi="['combat:userWb:remove']"
            >授权</el-button
          >
          <el-button
            v-else-if="returnAuth(scope.row)"
            size="mini"
            type="text"
            icon="el-icon-switch-button"
            @click="handleAuth(scope.row)"
            v-hasPermi="['combat:userWb:remove']"
            >重新授权</el-button
          >
          <el-button
            v-else-if="scope.row.token && !returnAuth(scope.row)"
            size="mini"
            type="text"
            icon="el-icon-switch-button"
            v-hasPermi="['combat:userWb:remove']"
            >授权成功</el-button
          >
          <el-button
            v-if="scope.row.token && !returnAuth(scope.row)"
            size="mini"
            type="text"
            @click="handleRelease(scope.row)"
            icon="el-icon-switch-button"
            v-hasPermi="['combat:userWb:remove']"
            >发布内容</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form
        inline
        ref="form"
        :model="form"
        :rules="rules"
        label-width="130px"
      >
        <el-form-item label="社交账号ID" prop="userId">
          <el-input
            size="small"
            v-model="form.userId"
            placeholder="请输入用户社交账号id"
          />
        </el-form-item>
        <el-form-item label="用户类型" prop="userType">
          <el-select
            clearable
            v-model="form.userType"
            placeholder="请选择用户类型"
          >
            <el-option label="重保用户" value="重保用户"></el-option>
            <el-option label="非重保用户" value="非重保用户"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="社交账号名称" prop="userName">
          <el-input
            size="small"
            v-model="form.userName"
            placeholder="请输入用户社交账号名称"
          />
        </el-form-item>
        <el-form-item label="用户电话" prop="userPhone">
          <el-input
            size="small"
            v-model="form.userPhone"
            placeholder="请输入用户电话"
          />
        </el-form-item>
        <el-form-item label="IP属地" prop="userIp">
          <el-input
            size="small"
            v-model="form.userIp"
            placeholder="请输入用户IP属地"
          />
        </el-form-item>
        <el-form-item label="关注量" prop="userFocusNum">
          <el-input
            size="small"
            v-model="form.userFocusNum"
            placeholder="请输入用户关注量"
          />
        </el-form-item>
        <el-form-item label="粉丝量" prop="userFansNum">
          <el-input
            size="small"
            v-model="form.userFansNum"
            placeholder="请输入用户粉丝量"
          />
        </el-form-item>
        <el-form-item label="家庭住址" prop="userHomeAddr">
          <el-input
            size="small"
            v-model="form.userHomeAddr"
            placeholder="请输入家庭住址"
          />
        </el-form-item>
        <el-form-item label="家庭住址纬度" prop="userHomeLat">
          <el-input
            size="small"
            v-model="form.userHomeLat"
            placeholder="请输入家庭住址纬度"
          />
        </el-form-item>
        <el-form-item label="家庭住址经度" prop="userHomeLon">
          <el-input
            size="small"
            v-model="form.userHomeLon"
            placeholder="请输入家庭住址经度"
          />
        </el-form-item>
        <el-form-item label="工作地址" prop="userWorkAddr">
          <el-input
            size="small"
            v-model="form.userWorkAddr"
            placeholder="请输入工作地址"
          />
        </el-form-item>
        <el-form-item label="工作地址纬度" prop="userWorkLat">
          <el-input
            size="small"
            v-model="form.userWorkLat"
            placeholder="请输入工作地址纬度"
          />
        </el-form-item>
        <el-form-item label="工作地址经度" prop="userWorkLon">
          <el-input
            size="small"
            v-model="form.userWorkLon"
            placeholder="请输入工作地址经度"
          />
        </el-form-item>
        <!-- <el-form-item label="用户平台" prop="userPlate">
          <el-select
            v-model="form.userPlate"
            placeholder="请选择用户平台"
            clearable
          >
            <el-option
              v-for="item in dict.type.user_platform"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button class="inBtn" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 二维码弹窗 不可以点击空白关闭-->
    <el-dialog
      title="授权登陆"
      :visible.sync="qrCodeoOen"
      width="400px"
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :before-close="beforeCloseFn"
    >
      <img :src="qrCodeUrl" alt="二维码" style="width: 100%; height: 100%" />
    </el-dialog>
    <!-- 发布内容弹窗 -->
    <el-dialog
      title="发布内容"
      :visible.sync="releaseDialog"
      width="600px"
      height="400px"
      :close-on-click-modal="false"
      append-to-body
    >
      <div v-if="releaseDialog">
        <!-- tab切换 -->
        <el-tabs v-model="activeName" @tab-click="handleClick" @close="handleClose">
          <el-tab-pane label="发布内容" name="first">
            <!-- 文本和图片 -->
            <el-input type="textarea" v-model="content" placeholder="请输入内容" ></el-input>
            <!-- 图片上传多个图片-->
            <image-upload
              ref="imageUploadRef"
              style="margin-top: 10px;"
              :max-count="9"
              :file-type="['jpg', 'png', 'gif','jpeg']"
              @input="handleSuccess"
            />
            <!-- 发布 -->
            <el-button type="primary" @click="handleReleaseContent">发布</el-button>
          </el-tab-pane>
          <el-tab-pane label="处理社交关系" name="second">
            <div>
              <!-- 展示chuliinputList -->
              <div style="margin-bottom: 10px;">
                <el-tag
                  v-for="(item,index) in chuliinputList"
                  :key="index"
                  closable
                  @close="removeFromArray(index)"
                  style="margin-right: 8px; margin-bottom: 8px;"
                >
                  {{item}}
                </el-tag>
                <div v-if="chuliinputList.length === 0" style="color: #999; font-size: 14px;">
                  暂无用户ID，请在下方输入框中输入用户ID并按回车添加
                </div>
              </div>
            </div>
            <el-row>
              <el-col :span="12">
                <el-select v-model="chuliType" placeholder="请选择">
                  <el-option label="关注" value="first"></el-option>
                  <el-option label="取消关注" value="second"></el-option>
                </el-select>
              </el-col>
              <el-col :span="12">
                <el-input v-model="chuliinput" placeholder="请输入用户ID" @keyup.enter.native="handleAddToArray"></el-input>
              </el-col>

            </el-row>
            <el-row style="margin-top: 10px;">

              <el-col :offset="18" :span="6">
                <el-button type="primary" @click="handleReleaseRelation">处理社交关系</el-button>
              </el-col>
            </el-row>
          </el-tab-pane>

        </el-tabs>
      </div>
    </el-dialog>
    <!-- 批量导入弹窗 -->
    <el-dialog
      title="批量导入"
      :visible.sync="importDialog"
      width="600px"
      append-to-body
    >
    <!-- 模板下载 -->
    <div style="margin-bottom: 10px;">
      <el-button type="primary" @click="handleDownloadTemplate">下载模板</el-button>
    </div>
      <file-upload :uploadFileUrlIn="'/userlocation/user/imports'" :uploadSucessFn="uploadSucessFn" ref="uploadRef" :fileType="['xlsx', 'xls']"></file-upload>
    </el-dialog>
  </div>
</template>

<script>
import { getQR, checkQR,getQRNew } from "@/api/combat/userWb";

import {
  listUser,
  updateUser,
  addUser,
  delUser,
  addUserFocus,
  cancelUserFocus,
  releaseContent
} from "@/api/combatUser/importantUser";
import {
  crawlallUser,
  crawlMoreUser,
  crawlUser,
} from "../../../api/combatUser/combat";
import {forwardFn } from "@/api/combat/userWb";

export default {
  name: "User",
  dicts: ["user_platform"],
  data() {
    return {
      importDialog: false, //批量导入弹窗是否打开
      currentUser: {}, //当前选中的用户
      contentImg: [], //内容图片
      content: '', //内容
      activeName: 'first', //当前选中的tab
      chuliType: 'first', //当前选中的tab
      chuliinput: '', //当前选中的tab
      chuliinputList: [], //当前选中的tab
      releaseDialog: false, //发布内容弹窗是否打开
      qrCodeUrl: "", //二维码图片的url
      qrCodeoOen: false, //二维码弹窗是否打开
      timer: null, //定时器
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        userName: null,
        userNickname: null,
        userIp: null,
        userFocusNum: null,
        userFansNum: null,
        userHomeAddr: null,
        userHomeLat: null,
        userHomeLon: null,
        userWorkAddr: null,
        userWorkLat: null,
        userWorkLon: null,
        userPlate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        //账号id
        userId: [
          { required: true, message: "账号id不能为空", trigger: "change" },
        ],
        //电话必填
        userPhone: [
          { required: true, message: "用户电话不能为空", trigger: "change" },
        ],
        //经纬度必填
        userHomeLat: [
          {
            required: true,
            message: "家庭住址纬度不能为空",
            trigger: "change",
          },
        ],
        userHomeLon: [
          {
            required: true,
            message: "家庭住址经度不能为空",
            trigger: "change",
          },
        ],
        userWorkLat: [
          {
            required: true,
            message: "工作地址纬度不能为空",
            trigger: "change",
          },
        ],
        userWorkLon: [
          {
            required: true,
            message: "工作地址经度不能为空",
            trigger: "change",
          },
        ],
        //用户类型必填
        userType: [
          { required: true, message: "用户类型不能为空", trigger: "change" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 下载模板 当前目录下 */
    handleDownloadTemplate(){
      //从minio中获取  get请求
    //http://192.168.0.121:9000/%E9%87%8D%E4%BF%9D%E7%94%A8%E6%88%B7%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx
    window.open('http://192.168.0.121:9000/combat/%E9%87%8D%E4%BF%9D%E7%94%A8%E6%88%B7%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx');

    },
    beforeCloseFn(){
      //关闭轮询的请求
      if(this.timer){
        this.clearInterval(this.timer)
      }
    },


    /** 批量导入成功 */
    uploadSucessFn(res, file) {
      console.log('resresresres',res);
      //res.msg 是一个html格式的数据 直接展示再一个弹框中
      this.$message.success(res.msg);
      console.log('filefilefilefile',file);
      this.$refs.uploadRef.closeLoading();
      this.importDialog = false;
    },
    /**发布内容*/
    handleReleaseContent(){
      //通过逗号将其分隔成数组
      let imglist = [];
      if(this.contentImg.length > 0){
        imglist  = this.contentImg.split(',');
      }
      if(this.content == ''){
        this.$message.error('请输入内容');
        return;
      }
      console.log('currentUsercurrentUser',this.currentUser);
      releaseContent({
        userId: this.currentUser.userId,
        content: this.content,
        imgList: imglist
      }).then(res => {
        console.log(res);
        if(res.code == 200){
          this.$message.success('发布成功');
          this.content = '';
          this.contentImg = [];
          this.handleClose();
        }else{
          this.$message.error('发布失败');
          this.content = '';
          this.contentImg = [];
        }
      });
    },
    handleSuccess(res){
      console.log(res);
      this.contentImg = res;
    },
    handleError(err){
      console.log(err);
      this.$message.error('上传失败');
    },
    handleClick(tab){
      console.log(tab);
      //如果tab为second，则清空chuliinputList
      if(tab.name == 'second'){
        this.chuliinputList = [];
        this.chuliinput = '';
      }

      //如果tab为first，则将chuliinput的值放到数组中
      if(tab.name == 'first'){
        this.content = '';
        this.contentImg = [];
      }
    },

    handleClose(){
      console.log('触发handleClose');
      //图片清空
      this.contentImg = [];
      this.currentUser = {};
      this.releaseDialog = false;
      this.activeName = 'first';
      this.chuliType = 'first';
      this.chuliinputList = [];
      this.chuliinput = '';
      this.content = '';
      this.contentImg = [];
    },
    handleAddToArray(){
      //将chuliinput的值放到数组中
      if(this.chuliinput.trim() === '') {
        this.$message.warning('请输入用户ID');
        return;
      }
      this.chuliinputList.push(this.chuliinput);
      //清空chuliinput
      this.chuliinput = '';
      console.log(this.chuliinputList);
    },
    handleReleaseRelation(row){
      console.log(this.chuliType,this.chuliinputList);
      //判断this.chuliinputList是否为空
      if(this.chuliinputList.length == 0){
        this.$message.error('请先添加用户ID到列表中');
        return;
      }

      if(this.chuliType == 'first'){
        //关注
        console.log('关注');
        //调用接口关注
        addUserFocus({
          userId: this.currentUser.userId,
          targetUserIds: this.chuliinputList
        }).then(res => {
          console.log(res);
          this.$message.success('关注成功');
          this.chuliinputList = [];
          this.handleClose();

        });
      }else{
        //取消关注
        console.log('取消关注');
        //调用接口取消关注
        cancelUserFocus({
          userId: this.currentUser.userId,
          targetUserIds: this.chuliinputList
        }).then(res => {
          console.log(res);
          this.$message.success('取消关注成功');
          this.chuliinputList = [];
          this.handleClose();
        });
      }
    },
    /**发布内容*/
    handleRelease(row) {
     //打开一个弹窗选择发布内容 还是处理社交关系
     this.currentUser = row;
     this.releaseDialog = true;
    },
    // 时间大于7天，则显示重新授权
    returnAuth(row) {
      if (row.authTime) {
        //获取当前时间
        const currentTime = new Date();
        const authTime = new Date(row.authTime);
        // 计算时间差
        const timeDiff = currentTime - authTime;
        // 将时间差转换为小时
        const hours = Math.floor(timeDiff / (1000 * 60 * 60));
        // 如果时间差大于7天，则返回true
        return hours > 3*24;
      }
    },
    /** 查询用户信息列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then((response) => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        userName: null,
        userNickname: null,
        userIp: null,
        userFocusNum: null,
        userFansNum: null,
        userHomeAddr: null,
        userHomeLat: null,
        userHomeLon: null,
        userWorkAddr: null,
        userWorkLat: null,
        userWorkLon: null,
        userPlate: null,
        userType: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 批量导入按钮操作 */
    handleImport(){
      this.importDialog = true;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加重保用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      this.form = row;
      this.open = true;
      this.title = "修改重保用户";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateUser(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              // 调用算法
              this.suanfa2(this.form.userId);
            });
          }
        }
      });
    },
    /**授权*/
    handleAuth(data) {
      let oldToken = data.token;
      if (data) {
        //调用接口获取二维码
        getQRNew(data.userPhone?data.userPhone:'').then((res) => {
          //返回的有二维码图片组装成base64
          const qrCodeUrl = res.data.imgUrl;
          // 将二维码图片显示在页面上
          this.qrCodeUrl = qrCodeUrl;
          this.qrid = res.data.qrid;
          //打开弹窗
          this.qrCodeoOen = true;
          //轮询列表查询接口  如果接口中token有值的话，则说明授权成功关闭弹窗
          this.timer = setInterval(() => {
            this.closeQRCode(res.data.qrid, data.userId);
          }, 2000);
        });
      } else {
        this.$message.error("请联系管理员！");
        return;
      }
    },
    //轮询详情接口
    closeQRCode(qrid, userId) {
      checkQR(qrid, userId).then((res) => {
        if (res.code == 200) {
          if (res.data.retcode == "200") {
            this.qrCodeoOen = false;
            clearInterval(this.timer);
            //刷新列表
            this.getList();
            this.$message.success("授权成功");
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除用户信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delUser(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "userlocation/user/export",
        {
          ...this.queryParams,
        },
        `user_${new Date().getTime()}.xlsx`
      );
    },
    handleCaiji(row) {
      console.log('rowrowrowrow',row)
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认采集用户信息编号为"' + ids + '"的数据项？')
        .then(function () {
          if (row.userId) {
            return crawlUser(ids);
          } else {
            this.$message.error("该数据缺少必要参数用户id，请联系管理员！");
          }
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("采集成功");
          //等待两秒后使用一个post请求请求算法
          setTimeout(() => {
            this.suanfa(row.userId);
          }, 2000);
        })
        .catch(() => {});
    },
    suanfa(id){
    ///combat/funcation/forward
     forwardFn({
      "type":"follow",
      "userId":id,
      "usertype":"3"
     }).then((res)=>{
      console.log('resresresres',res)
     })
    },
    suanfa2(id){
    ///combat/funcation/forward
     forwardFn({
      "type":"follow",
      "userId":id,
      "usertype":"4"
     }).then((res)=>{
      console.log('resresresres',res)
     })
    },
    /** 采集按钮操作 */
    handleAcquisition(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认采集用户信息编号为"' + ids + '"的数据项？')
        .then(function () {
          if (row.id) {
            return crawlUser(ids);
          } else {
            return crawlMoreUser(ids);
          }
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("采集成功");
        })
        .catch(() => {});
    },
    /**全部采集*/
    crawlallUser() {
      this.$modal
        .confirm("是否确认采集全部用户信息？")
        .then(function () {
          return crawlallUser();
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("采集成功");
        })
        .catch(() => {});
    },
    /**详情页面*/
    toDetailsPage(data) {
      if (!data.userId) {
        this.$message.error("该数据缺少参数，请联系管理员！");
        return;
      }
      //没有认证
      // if (!data.token) {
      //   this.$message.error("该数据未认证，请联系管理员！");
      //   return;
      // }
      this.$router.push(
        "/networkUser/userDetails?id=" + data.id + "&userId=" + data.userId
      );
    },
    removeFromArray(index) {
      this.chuliinputList.splice(index, 1);
    },
  },
};
</script>
<style scoped>
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.inBtn {
  color: white;
  width: 106px;
  background: linear-gradient(270deg, #2dbffd 0%, #0e5fff 100%);
  border-radius: 4px 4px 4px 4px;
}

::v-deep .el-pager li.active {
  background: linear-gradient(270deg, #2dbffd 0%, #0e5fff 100%) !important;
}
</style>
